package com.shuqing.controller;

import com.shuqing.domain.Record;
import com.shuqing.domain.User;
import com.shuqing.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/record")
public class RecordService {

    @Autowired
    private com.shuqing.service.RecordService recordService;

    @RequestMapping("/searchRecords")
    public ModelAndView searchRecords(Record record, Integer pageNum, Integer pageSize,HttpServletRequest request){
        if(pageNum == null){
            pageNum = 1;
        }
        if (pageSize == null){
            pageSize = 10;
        }
//        获取当前等登录的用户的信息
        User user = (User)request.getSession().getAttribute("USER_SESSION");
        PageResult pageResult = recordService.searchRecords(record, user, pageNum, pageSize);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("record");
//        将查询结果返回封面页
        modelAndView.addObject("pageResult", pageResult);
//        将调查结果回显到查询的输入框
        modelAndView.addObject("search", record);
//        显示页码
        modelAndView.addObject("pageNum", pageNum);
        //将当前查询的控制器路径返回到页面，页码变化时继续项该路径发送请求 （当前页面，改变页码时，路径不变）
        modelAndView.addObject("gourl",request.getRequestURI());
        return modelAndView;
    }
}
